define(function(require, exports, module) {
	var $ = require('jquery')
	var Spine = require('spine')
	require('spine.ajax')
	var File = Spine.Model.sub()
	File.configure('File', 'filename', 'type', 'modTime', 'path')
	File.extend(Spine.Model.Ajax)
	File.extend({
		fetchByPath: function(path) {
			if (!path) path = '/'
			return File.fetch({
				type: 'GET',
				url: '/list',
				data: $.param({
					'path': path
				})
			})
		},
		create: function(params, remote) {
			this.__super__.constructor.create.call(this, params, {
				ajax: false
			})
			if (remote) {
				$.post('/create', {
					path: params.path
				}, function(data) {
					console.log(data)
				})
			}

		}
	})
	File.include({
		destroy: function(remote) {
			this.constructor.__super__.destroy.call(this, {
				ajax: false
			})
			if (remote) {
				$.post('/delete', {
					'path': this.path
				}, function(data) {})
			}
		},
		updateAttributes: function(attrs, remote) {
			var origin, target
			origin = this.path
			console.log(origin)
			this.constructor.__super__.updateAttributes.call(this, attrs, {
				ajax: false
			})
			target = this.path
			console.log(target)

			if (remote) {
				$.post('/update', {
					'origin': origin,
					'target': target
				}, function(data) {
					console.log(data)
				})
			}

		}
	})
	var Location = Spine.Model.sub()
	Location.configure('Location', 'name', 'path')

	var Upload = Spine.Model.sub()
	Upload.configure('Upload', 'name', 'path')

	var Directory = Spine.Model.sub()
	Directory.configure('Directory', 'type', 'path')

	module.exports = {
		File: File,
		Location: Location,
		Upload: Upload,
		Directory: Directory
	}
})